<template>
    <h2>会员等级修改</h2>
    <table border="1">
        <tr>
            <td>等级名称</td>
            <td>
                <input type="text" v-model="state.levelName">
            </td>
        </tr>
        <tr>
            <td>最低消费金额</td>
            <td><input type="text" v-model="state.lowMoney"></td>
        </tr>
        <tr>
            <td>最高消费金额</td>
            <td><input type="text" v-model="state.highMoney"></td>
        </tr>
        <tr>
            <td>折扣</td>
            <td><input type="text" v-model="state.zhenko"></td>
        </tr>
        <tr>
            <td>成长值</td>
            <td><input type="text" v-model="state.grow"></td>
        </tr>
        <tr>
            <td>翻倍</td>
            <td><input type="text" v-model="state.speed"></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" value="修改" @click="upd"></td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import {reactive,toRefs,onMounted} from 'vue';
import {useRouter,useRoute} from 'vue-router';

let data=reactive({
    state:{
  "levelName":'',
  "lowMoney":'',
  "highMoney":'',
  "zhenko":'',
  "speed": '',
  "grow":'',
  "levelState":1
}
})
const {state}=toRefs(data);
const router=useRouter();
const route=useRoute();

onMounted(()=>{
    getdata();
})

const getdata=()=>{
axios({
    url:'/api/Member/UpdteMember',
    method:'get',
    params:{
        id:route.query.id
    }
})
.then(res=>{
    console.log(res);
    state.value=res.data.data;
})
.catch(err=>{
    console.log(err);
})
}



const upd=()=>{
    if(state.value.levelName==''){
        alert('等级名称不能为空');
        return;
    }
    if(state.value.lowMoney==''){
        alert('最低消费金额不能为空');
        return;
    }
    if(state.value.highMoney==''){
        alert('最高消费金额不能为空');
        return;
    }
    if(state.value.zhenko==''){
        alert('折扣不能为空');
        return;
    }
    if(state.value.speed==''){
        alert('翻倍不能为空');
        return;
    }
    if(state.value.grow==''){
        alert('成长值不能为空');
        return;
    }

    axios({
        url:'/api/Member/XiuMember',
        method:'put',
        data:state.value
    })
    .then(res=>{
        console.log(res);
        state.value=res.data.data;
        if(res.data.data==1)
        {
            alert('修改成功');
            router.push('/Memlv');
        }
        else if(res.data.data==0)
        {
            alert('会员名重复');
            return;
        }
        else{
            alert('修改失败');
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>